package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.HouseDynamic;
import com.realtyManage.springboot.Model.Do.ProjectDetail;
import com.realtyManage.springboot.Model.Do.UserTask;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 楼盘动态
 *
 * @author 杭州素色网络科技有限公司
 * @since 2019-10-14
 */

@Repository
public interface HouseDynamicRepository extends JpaRepository<HouseDynamic, Integer>, JpaSpecificationExecutor<HouseDynamic> {

    @Transactional
    @Modifying
    @Query("update HouseDynamic a set " +
            "a.userImg = CASE WHEN :#{#houseDynamic.userImg} IS NULL THEN a.userImg ELSE :#{#houseDynamic.userImg} END ," +
            "a.userId = CASE WHEN :#{#houseDynamic.userId} IS NULL THEN a.userId ELSE :#{#houseDynamic.userId} END ," +
            "a.userNam = CASE WHEN :#{#houseDynamic.userNam} IS NULL THEN a.userNam ELSE :#{#houseDynamic.userNam} END ," +
            "a.insertTime = CASE WHEN :#{#houseDynamic.insertTime} IS NULL THEN a.insertTime ELSE :#{#houseDynamic.insertTime} END ," +
            "a.center = CASE WHEN :#{#houseDynamic.center} IS NULL THEN a.center ELSE :#{#houseDynamic.center} END " +
            "where a.id = :#{#houseDynamic.id}")
    int updateHouseDynamic(@Param("houseDynamic") HouseDynamic houseDynamic);

    @Modifying
    @Query(value = "SELECT * FROM `house_dynamic` ORDER BY insert_time DESC",nativeQuery = true)
    List<HouseDynamic> showHouseDynamic();

    @Transactional
    @Modifying
    @Query(value="delete from house_dynamic where id in (?1) ",nativeQuery=true)
    int deleteHouseDynamic(List ids);

}
